package main.chapter6.lambda;/**
 * @Author xy
 * @Date 2020/6/21 22:22
 * @Description
 */

import javax.swing.*;
import javax.swing.Timer;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.*;
import java.util.List;

/**
 * 文件名称： main.chapter6.lambda.LambdaTest.java</br>
 * 初始作者： xy</br>
 * 创建日期： 2020/6/21 22:22</br>
 * 功能说明： TODO <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者        日期       修改内容<br/>
 * ================================================<br/>
 * Copyright (c) 2020-2021 .All rights reserved.<br/>
 */
public class LambdaTest {
/*    public static void main(String[] args) {
        String[] planets = new String[]{"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"};
        System.out.println(Arrays.toString(planets));
        System.out.println("Sorted in dictionary order:");
        Arrays.sort(planets);
        System.out.println(Arrays.toString(planets));
        System.out.println("Sorted by length:");
        Arrays.sort(planets,(first,second)->first.length()-second.length());
        System.out.println(Arrays.toString(planets));

        Timer timer = new Timer(1000,e -> System.out.println("The time is "+ new Date()));
        timer.start();

        JOptionPane.showMessageDialog(null,"Quit program?");
        System.exit(0);
    }*/

    /**
     * 使用::运算符分隔方法名与对象或类名，主要有三种情况：
     * 1.object::instanceMethod 方法引用等价于向方法传递参数的lambda表达式。
     * 2.Class::instanceMethod  第一个参数会成为方法的隐式参数，后面的参数向方法传递参数的lambda表达式
     * 3.Class::staticMethod  所有参数都传递到静态方法作为参数的lambda表达式
     * @param args
     */
    public static void main(String[] args) throws InterruptedException {
        List<String> arrayList = new ArrayList<String>();
        arrayList.add("a");
        arrayList.add("b");
        arrayList.add("c");
        arrayList.add("d");
        arrayList.removeIf(Objects::isNull);
        repeatMessage("hello",1000);
        Thread.sleep(50000);
    }

    public static void repeatMessage(String text, int delay){
        ActionListener actionListener = event->{
            System.out.println(text);
            Toolkit.getDefaultToolkit().beep();
        };
        new Timer(delay,actionListener).start();
    }
}
